package com.hbpu.encap.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Homework01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, InstantiationException {
        Class<?> aClass = Class.forName("com.hbpu.encap.reflection.PrivateTest");
        Object o = aClass.getDeclaredConstructor().newInstance();
        Field name = aClass.getDeclaredField("name");
        name.setAccessible(true);
        name.set(o, "haha");
        Method getName = aClass.getMethod("getName");
        System.out.println(getName.invoke(o));
    }
}

class PrivateTest {
    private String name = "Hellokitty";

    public String getName() {
        return name;
    }
}